import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/pages/student/readingRecords.dart';
import 'package:ichinesereader/pages/student/readingRecordsLeveled.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/themes/pageStyles.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/pages/assessment/assessmentBooksRecords.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerIndividual.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import 'package:ichinesereader/widgets/sidebars/individualSidebar.dart';
import '../../themes/appTheme.dart';

class IndividualReportsPage extends StatefulWidget {
  static const String routeName = '/individual/reports';

  @override
  State<IndividualReportsPage> createState() => _IndividualReportsPageState();
}

class _IndividualReportsPageState extends State<IndividualReportsPage> {
  final box = Hive.box('appconfig');

  @override
  void initState() {
    Get.put(ReportsController());
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<ReportsController>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build IndividualReportsPage');

    final PageStyles _pageStyles = PageStyles();
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;
    int _selectedSidebarItem = RoutePages.individualPageItems
        .indexWhere((page) => page.route == Get.currentRoute);

    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: isSmallScreen ? CustomAppBar(title: 'Reports') : null,
        drawer: isSmallScreen ? IndividualAppDrawer() : null,
        body: Container(
          decoration: _pageStyles.pageBoxDecoration(),
          child: Row(
            children: [
              Visibility(
                  visible: !isSmallScreen,
                  child: Container(
                      child: IndividualSidebarX(
                          selectedIndex: _selectedSidebarItem,
                          isBigScreen: isBigScreen))),
              Expanded(
                flex: 10,
                child: Container(
                  margin: _pageStyles.mainContainerPageEdgeInsets(),
                  child: Column(
                    children: [
                      Expanded(
                        flex: 1,
                        child: Stack(
                          alignment: Alignment.center,
                          children: [
                            Container(
                              margin: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 6.0),
                              decoration: BoxDecoration(
                                color: Get.isDarkMode
                                    ? AppTheme.colors.darkTheme2
                                    : Colors.black.withOpacity(0.1),
                                borderRadius: BorderRadius.circular(6),
                              ),
                            ),
                            Container(
                              child: _pageStyles.buildTabBar([
                                'Leveled Readings',
                                'Latest Readings',
                                'Assessments'
                              ]),
                            ),
                          ],
                        ),
                      ),
                      Expanded(
                        flex: 11,
                        child: Container(
                          //margin: EdgeInsets.only(left: 6.0),
                          child: TabBarView(
                            children: [
                              LeveledReadingRecords(),
                              LatestReadingRecords(),
                              AssessmentBookRecords(),
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
